﻿Public Class AccountExplorer
    Inherits ExplorerTreeList

    Private aEditPanePL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub





    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        ' Memory management / Help the GC
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If

        If aEditPanePL IsNot Nothing Then
            aEditPanePL.Dispose()
            aEditPanePL = Nothing
        End If

        Dim guidEnfant As Guid
        Dim aPLName As String
        Dim DescriptionLang As String = "_PRM"
        Dim aPaneMetaQueryName As String
        Dim aMetaquerie As MetaQuery
        Dim frmCaption As String = "Account List"        'DeskTopManager.GetMessage("CONNECT") to be implemented when metastring has code

        Try
            guidEnfant = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
            aPLName = DirectCast(NodeDataRow("PL"), String)

            aPaneMetaQueryName = DirectCast(NodeDataRow("MetaQuerie"), String)
            aMetaquerie = MetaQuery.GetMetaQueryByName(aPaneMetaQueryName)

            'c'est ici qu'on bind les info du noeud qui articule le Edit PANE
            aEditPanePL = PLBase.CreateInstanceOf(aPLName, aPaneMetaQueryName)

            aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = aEditPanePL, .SecureGrid = True, .Name = aMetaquerie.Caption, .FormCtrlCD = MyBase.PanelName}
            If Not Guid.Empty.Equals(guidEnfant) Then
                aEditPanePL.SQLWhere = String.Format("{0} = '{1}'", aMetaquerie.GUIDField, guidEnfant)
                If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
                    DescriptionLang = "_ALT"
                End If
                If NodeDataRow.Table.Columns.Contains("Code") AndAlso NodeDataRow.Table.Columns.Contains("Description") Then
                    frmCaption = String.Format("{0} - {1}", NodeDataRow("Code"), NodeDataRow("Description" & DescriptionLang))
                Else
                    frmCaption = "Code, " + "Description" & DescriptionLang
                End If

            End If
        Catch ex As Exception
            MessageWindow.ShowMessage(ex)
        End Try
        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub



    Private Sub AccountExplorer_Load(sender As Object, e As EventArgs) Handles Me.Load
        TreeActionOptionListLoad()
        MetaControlTreeListActionOptionList.ApplySecurity()
    End Sub
End Class
